# geometric test using the head_neck geometry
# tests both methods of adding elements - passing the points they are
# going to connect to, and their geometric parameters

#!/usr/bin/env python
from scipy import *
from enthought.mayavi import mlab
import sys
sys.path.append( '../' )

from field import template_fields
from field import geometric_field
from field.topology import element_types

# head neck parameters
h_r = 20.0
n_l = 30.0
n_r = None
eval_density = 10

# instantiate a new geometric_field with an empty 2D ensemble_field
gf = geometric_field.geometric_field( 'test', 3, field_dimensions = 2,  field_basis = 'triangular_quadratic_2d' )

# make a head_neck mesh (ensemble_field + precomputed parameters)
(head_neck, xparam, yparam, zparam, cp) = template_fields.head_neck( h_r, n_l, n_r, )

# add head_mesh mesh and parameters to the geometric field
gf.add_element_with_parameters( head_neck, [xparam, yparam, zparam] )

# add some points and store their point numbers in p
p = []
p.append( gf.add_geometric_point([[14.0],[6.0],[-50.0]], name = 'test1') )
p.append( gf.add_geometric_point([[13.4],[10.3],[-55.0]], name = 'test2') )
p.append( gf.add_geometric_point([[6.0],[13.0],[-50.0]], name = 'test3') )

# create a quadratic triangular element
e_1 = element_types.create_element( 'tri6' )

# add element to mesh by specifying points
p.reverse()
epoints = [0,1,2] + p
gf.add_element( e_1, epoints, 1 )

# create another element
e_2 = element_types.create_element( 'tri6' )

# add to mesh using parameters (1st 3 points are at the same position as
# the geometric_points added above)
e_2_x = [ [14.0], [13.4], [6.0], [10.0], [13.0], [14.5] ]
e_2_y = [ [6.0], [10.3], [13.0], [15.0], [10.0], [5.0] ]
e_2_z = [ [-50.0], [-55.0], [-50.0], [-65.0], [-70.0], [-65.0] ]
gf.add_element_with_parameters( e_2, [e_2_x, e_2_y, e_2_z] ) 

gf.display_geometric_field( eval_density, field_glyph = 'sphere' )

